#!/bin/bash

# 获取脚本所在目录
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"

# 创建日志目录
mkdir -p logs

# 启动前端
cd "$SCRIPT_DIR/vue-admin-template"
npm run dev > ../logs/frontend.log 2>&1 &
echo $! > ../logs/frontend.pid

# 等待前端启动
sleep 3

# 启动后端
cd "$SCRIPT_DIR/lumen"
php -S localhost:8000 -t public > ../logs/backend.log 2>&1 &
echo $! > ../logs/backend.pid

echo "前端: http://localhost:9528"
echo "后端: http://localhost:8000"

# 等待中断信号
trap 'kill $(cat logs/frontend.pid) $(cat logs/backend.pid) 2>/dev/null; rm -f logs/*.pid; exit' INT TERM

wait
